/*
 * @Author: shawnxiao
 * @Date: 2021-12-07 18:38:16
 * @LastEditTime: 2021-12-17 14:41:19
 * @FilePath: /vite2-vue3-ts-antd/src/apis/Login/index.ts
 */

import request, { instanceProps } from '@/common/utils/request'

import { getParentUrl } from '@/common/utils'

// const isMock = import.meta.env.MODE  === 'development' ? false : false
// const domain = isMock ? './api' : `${import.meta.env.VITE_APP_API_URL}`
// const prefix = import.meta.env.MODE === 'development' ? '' : '' // 接口前缀
// // 接口路径
// const basePath = `${domain}${prefix}`

export async function checkLoginTokenFn(params: any) {
  // 动态区分lab和非lab服务环境,拼接sso判断是否登录接口路径
  const parentUrl: string = getParentUrl() || ''
  const originParent = parentUrl ? parentUrl.split('://')[1].split('/')[0] : ''
  const url = parentUrl || `${import.meta.env.VITE_APP_LOGIN_URL}`
  const path = parentUrl ? (parentUrl.includes('lab') ? 'sso.lab' : 'sso') : 'sso.lab'
  const origin = originParent || (url.includes('lab') ? 'app.lab.clickpaas.com' : 'app.clickpaas.com')
  const protocol = parentUrl ? (parentUrl?.includes('https') ? 'https' : 'http') : 'https'

  return request({
    url: `${protocol}://${path}.${origin.split('app.')[1]}/api/sso/login/checkStatus?origin=${origin}`,
    method: 'get',
    model: null,
    params
  } as instanceProps)
}
